package com.jxdinfo.hussar.cloud.module.example.lift.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftDataHistoryDto;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftDataHistorySearchDto;
import com.jxdinfo.hussar.cloud.module.example.lift.model.LiftDataHistory;
import com.jxdinfo.hussar.cloud.module.example.lift.model.LiftNotice;
import com.jxdinfo.hussar.cloud.module.example.lift.service.LiftDataHistoryService;
import com.jxdinfo.hussar.engine.metadata.model.BaseEntity;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 升降机历史数据(LiftDataHistory)表控制层
 *
 * @author makejava
 * @since 2023-10-23 18:18:25
 */
@RestController
@RequestMapping("liftDataHistory")
public class LiftDataHistoryController  {
    /**
     * 服务对象
     */
    @Resource
    private LiftDataHistoryService liftDataHistoryService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param liftDataHistory 查询实体
     * @return 所有数据
     */
    @GetMapping
    public ApiResponse selectAll(Page<LiftDataHistory> page, LiftDataHistory liftDataHistory) {
        return ApiResponse.success(this.liftDataHistoryService.page(page, new QueryWrapper<>(liftDataHistory)));
    }

    /**
     * 历史数据
     * @param liftDataHistorySearchDto
     * @return
     */
    public ApiResponse<Page<LiftDataHistoryDto>> findByPage(LiftDataHistorySearchDto liftDataHistorySearchDto) {

        /*if(ObjectUtils.isNotEmpty(liftDataHistorySearchDto.getTyProjectCode())){
            liftDataHistorySearchDto.setTyProjectCode(liftDataHistorySearchDto.getTyProjectCode());
        }else{*/
        liftDataHistorySearchDto.setTyProjectCode("ProjectUtil.getProjectInfo().getProjectCode()");
        //}

        Page<LiftDataHistory> pageResult = liftDataHistoryService.findPage(liftDataHistorySearchDto);

       // ResultData<PageResult<LiftDataHistoryDto>> result = this.convertToDtoPageResult(pageResult);

        return ApiResponse.success();
    }
    @PostMapping("/findLineChart")
    public ApiResponse<List<LiftDataHistoryDto>> findLineChart(LiftDataHistorySearchDto liftDataHistorySearchDto) {

        /*if(ObjectUtils.isNotEmpty(liftDataHistorySearchDto.getTyProjectCode())){
            liftDataHistorySearchDto.setTyProjectCode(liftDataHistorySearchDto.getTyProjectCode());
        }else{
            liftDataHistorySearchDto.setTyProjectCode(ProjectUtil.getProjectInfo().getProjectCode());
        }*/

        liftDataHistorySearchDto.setTyProjectCode("ProjectUtil.getProjectInfo().getProjectCode()");
        List<LiftDataHistory> list = liftDataHistoryService.findLineChart(liftDataHistorySearchDto);
//        List<LiftDataHistoryDto> line = this.convertToDtos(list);
//
//        for (LiftDataHistoryDto liftDataHistoryDto : line) {
//            liftDataHistoryDto.setTime(DateUtils.formatDate(liftDataHistoryDto.getCollectionTime(),DateUtils.DEFAULT_TIME_FORMAT));
//        }
        return ApiResponse.success();
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ApiResponse selectOne(@PathVariable Serializable id) {
        return ApiResponse.success(this.liftDataHistoryService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param liftDataHistory 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ApiResponse insert(@RequestBody LiftDataHistory liftDataHistory) {
        return ApiResponse.success(this.liftDataHistoryService.save(liftDataHistory));
    }

    /**
     * 修改数据
     *
     * @param liftDataHistory 实体对象
     * @return 修改结果
     */
    @PutMapping
    public ApiResponse update(@RequestBody LiftDataHistory liftDataHistory) {
        return ApiResponse.success(this.liftDataHistoryService.updateById(liftDataHistory));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ApiResponse delete(@RequestParam("idList") List<Long> idList) {
        return ApiResponse.success(this.liftDataHistoryService.removeByIds(idList));
    }
}

